package com.joysuch.wwyt.api.mh.controller;

import com.joysuch.wwyt.api.mh.dto.MhMonitPointPushRequestDto;
import com.joysuch.wwyt.api.mh.dto.MhMonitPointPushResponseDto;
import com.joysuch.wwyt.api.mh.service.MonitPointConfigService;
import com.joysuch.wwyt.api.mh.service.MonitorPointDataAPIService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.mh.bean.MhMonitoringPointDtoo;
import com.joysuch.wwyt.repeatsubmit.NoRepeatSubmit;
import com.joysuch.wwyt.workflow.bean.WorkFlowExecuteTaskBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ActivitiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "API 监测点实时数据推送")
@RequestMapping("/api/mh/monitorPoint/")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MonitorPointAPIDataController {

    @Autowired
    private MonitorPointDataAPIService monitorPointDataAPIService;

    @PostMapping("/pushMonitorPointData")
    @ApiOperation(value = "推送监测点实时数据")
    public MhMonitPointPushResponseDto pushMonitorPointData(@RequestBody MhMonitPointPushRequestDto requestDto ) {
        log.info("The api /api/mh/monitorPoint/pushMonitorPointData called, dataList size ={} ...", requestDto.getData() ==null ? null : requestDto.getData().size());
        log.debug(" pushMonitorPointData request data : {} ", requestDto.toString() );
        if(requestDto.getTenantId() == null || requestDto.getOrgCode() == null){
            return  new MhMonitPointPushResponseDto(Status.PARAMETER_ERROR.getCode(),"请求参数 tenantId 或 orgCode 为空。");
        }
        try{
          monitorPointDataAPIService.pushMonitorPointData(requestDto.getData(), requestDto.getTenantId(), requestDto.getOrgCode());
        }catch (Exception e) {
            log.error("第三方监测点实时数据推送接口失败:", e);
            return new MhMonitPointPushResponseDto(Status.OPEN_SERVICE_FAILED.getCode(),e.getMessage());
        }
        return  new MhMonitPointPushResponseDto(Status.OPEN_SERVICE_SUCCESS);
    }

}
